<template>
  <a-card :bordered="false">
    <div>
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="客户名称">
              <a-input placeholder="请输入客户名称" v-model="customer.customerName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="getPage(1,10,customer.customerName)" icon="search">查询</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <div>
      <a-row>
        <a-col :span="24">
          <a-pagination v-model:current="current" :total="50" @change="changeCurrent(current)" show-less-items />
        </a-col>
      </a-row>
    </div>
  </a-card>
</template>


<script>
    import '@/assets/less/TableExpand.less'
    import { mixinDevice } from '@/utils/mixin'
    import { JeecgListMixin } from '@/mixins/JeecgListMixin'
    import {postAction} from '@/api/manage'
    import ACol from "ant-design-vue/es/grid/Col";

    export default {
        name: "customer",
      components: {ACol},
      data () {
        return {

          // 表头
          current:1,
          total:10,
          columns: [
            {
              title: '#',
              dataIndex: '',
              key:'rowIndex',
              width:60,
              align:"center",
              customRender:function (t,r,index) {
                return parseInt(index)+1;
              }
            },
            {
              title:'客户编号',
              align:"center",
              dataIndex: 'customerId'
            },
            {
              title:'客户名称',
              align:"center",
              dataIndex: 'customerName'
            },
            {
              title:'联系人',
              align:"center",
              dataIndex: 'contacts'
            },
            {
              title:'联系电话',
              align:"center",
              dataIndex: 'phoneNumber'
            },
            {
              title:'地址',
              align:"center",
              dataIndex: 'address'
            },
            {
              title:'备注',
              align:"center",
              dataIndex:'remarks',
            },
            {
              title: '操作',
              dataIndex: 'action',
              align:"center",
              fixed:"right",
              width:147,
              scopedSlots: { customRender: 'action' }
            }
            ],
          url: {
            listUrl: "/customer/list",
            deleteUrl: "/customer/delete",
            saveUrl:"/customer/save",
          },
          customer:{
            customerId:"",
            customerName:"",
            contacts:"",
            phoneNumber:"",
            address:"",
            remarks:""
          }
        }
      },
      created(){
        this.getPage(1,10,null);
      },
      methods:{
        delete(ids){
          postAction(this.url.deleteUrl,ids).then(resp=>{
            console.log(resp);
            if(resp.success){
              this.$message.success("删除成功!");
            }else{
              this.$message.info("操作失败");
            }
          })
        },
        getPage(page,rows,customer){
          var requestCustomer={page,rows,customer}
          postAction(this.url.listUrl,requestCustomer).then(resp=>{
            console.log(resp);
            for (let i = 0; i < resp.size; i++) {
              console.log(resp.records[i].customerId);
              // this.customerId=resp.records[i].customerId;
              // this.customerName=resp.records[i].customerName;
              // this.contacts=resp.records[i].contacts;
              // this.phoneNumber=resp.records[i].phoneNumber;
              // this.address=resp.records[i].address;
              // this.remarks=resp.records[i].remarks;
            }
          })
        },
        save(id,customer){
          postAction(this.url.saveUrl+"?customerId="+id,customer).then(resp=>{
            console.log(resp);
          })
        },
        changeCurrent(current){
          this.current=current;
          this.getPage(1,10,null);
        }
      }
    }
</script>

<style scoped>
  @import '~@assets/less/common.less';
</style>